<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>闭包之缓存</title>
</head>
<body>

</body>
<script>
    /**
    function test1() {
        let food = 'apple';
        let obj = {
            editFood(){
                if(food){
                    console.log('there food is ' + food);
                    food = ''
                }else {
                    console.log('there is nothing')
                }
            },
            pushFood(newFood){
                food = newFood;
            }
        };
        return obj
    }

    let person = test1();
    person.editFood();
    person.editFood();
    person.pushFood('banana');
    person.editFood();
    **/
</script>
<script>
    let edit ={
        food: 'apple',
        editFood() {
            if(this.food){
                console.log('2 there food is ' + this.food)
                this.food = ''
            }else {
                console.log('2 there is nothing')
            }
        },
        pushFood(newFood) {
            this.food = newFood
        }
    };
    edit.editFood();
    edit.editFood();
    edit.pushFood('banana');
    edit.editFood();
</script>
</html>
